import { DialogForm } from 'custom/index'
import { addScriptManagePage, updateScriptManagePage, getDepartments } from './api'

const addDialog = new DialogForm('DialogForm')

addDialog
  .title('新增')
  .postApi(addScriptManagePage)
  .useGroup('')
    .useDictSelect('companyNo', 'company').setProp('widthLabel', 'companyName').label('公司').required().setProp('onChange', (val) => {
      if (!val) {
        addDialog.setData('customPostType', '')
        addDialog.setData('customPostTypeName', '')
      } else if (val !== 'ALL') {
        addDialog.setData('customPostType', 'noneGroup')
        addDialog.setData('customPostTypeName', '无')
      }
    }).end()
    .useDictSelect('customPostType', 'customPostType').setProp('widthLabel', 'customPostTypeName').label('岗位分类').required().disabled(props => {
      return !(props.data.companyNo === 'ALL')
    }).end()
    .useItem('base').label('基数').required().end()
    .useItem('coefficient').label('系数（%）').required().end()

const editDialog = new DialogForm('DialogForm')
editDialog
  .title('编辑')
  .postApi(updateScriptManagePage)
  .useGroup('')
    .useDictSelect('companyNo', 'company').setProp('widthLabel', 'companyName').label('公司').required().setProp('onChange', (val) => {
      if (!val) {
        editDialog.setData('customPostType', '')
        editDialog.setData('customPostTypeName', '')
      } else if (val !== 'ALL') {
        editDialog.setData('customPostType', 'noneGroup')
        editDialog.setData('customPostTypeName', '无')
      }
    }).end()
    .useDictSelect('customPostType', 'customPostType').setProp('widthLabel', 'customPostTypeName').label('岗位分类').required().disabled(props => {
      return !(props.data.companyNo === 'ALL')
    }).end()
    .useItem('base').label('基数').required().end()
    .useItem('coefficient').label('系数（%）').required().end()

export { addDialog, editDialog }
